package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "sup基础属性接口")
@RestController
@RequestMapping("admin/product")
public class SpuManageController {

    @Autowired
    private ManageService manageService;

    //http://api.gmall.com/admin/product/ {page}/{limit}?category3Id=61
    @GetMapping("{page}/{limit}")
    public Result getSpuInfoPage(@PathVariable long page, @PathVariable long limit, SpuInfo spuInfo){
        Page<SpuInfo> infoIPage = new Page<>(page,limit);
        IPage<SpuInfo> spuInfoPageList = manageService.getSpuInfoPage(infoIPage,spuInfo);
        return Result.ok(spuInfoPageList);
    }
    //http://api.gmall.com/admin/product/baseSaleAttrList
    @GetMapping("baseSaleAttrList")
    public  Result baseSaleAttrList(){
        List<BaseSaleAttr> baseSaleAttrList = manageService.getbaseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }

    //http://api.gmall.com/admin/product/saveSpuInfo
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }


    //http://api.gmall.com/admin/product/spuImageList/{spuId}
    @GetMapping("spuImageList/{spuId}")
    public Result spuImageList(@PathVariable long spuId){
        List<SpuImage> spuImageList = manageService.getSpuImageList(spuId);
        return Result.ok(spuImageList) ;
    }

    //http://api.gmall.com/admin/product/spuSaleAttrList/{spuId}
    @GetMapping("spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable long spuId){
        List<SpuSaleAttr> spuSaleAttrList = manageService.getspuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }

    //http://api.gmall.com/admin/product/saveSkuInfo
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }
    //http://api.gmall.com/admin/product/list/{page}/{limit}
    @GetMapping("list/{page}/{limit}")
    public Result getSkuPageList(@PathVariable long page,@PathVariable long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page,limit);
        IPage<SkuInfo> skuInfoIPage = manageService.getPage(skuInfoPage);
        return Result.ok(skuInfoIPage);
    }

    //http://api.gmall.com/admin/product/onSale/{skuId}
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable long skuId){
        manageService.onSale(skuId);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/cancelSale/{skuId}
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable long skuId){
        manageService.cancelSale(skuId);
        return Result.ok();
    }

}
